package com.longge;

import java.util.TreeSet;

public class FindSecondMinimumValue {

    TreeSet<Integer> set = new TreeSet<>();

    public int findSecondMinimumValue(TreeNode root) {

        dfs(root);

        int k = 0;
        for (Integer num : set) {
            k++;
            if (k == 2) return num;
        }
        return -1;

    }

    private void dfs(TreeNode root) {
        if (root == null) return;
        set.add(root.val);
        dfs(root.left);
        dfs(root.right);
    }
}
